using FreeSql.DataAnnotations;

namespace SumerCoreDevOps.Domain.Entities;

/// <summary>
/// 系统配置实体
/// </summary>
[Table(Name = "system_configs")]
[Index("idx_config_key", "ConfigKey", true)] // 唯一索引
public class SystemConfig
{
    /// <summary>
    /// 配置 ID
    /// </summary>
    [Column(IsPrimary = true, IsIdentity = true)]
    public long Id { get; set; }

    /// <summary>
    /// 配置键（唯一）
    /// 例如：ControlApiPort, TcpServerPort, NodeDefaultPort
    /// </summary>
    [Column(StringLength = 100, IsNullable = false)]
    public string ConfigKey { get; set; } = null!;

    /// <summary>
    /// 配置值
    /// </summary>
    [Column(StringLength = 1000, IsNullable = false)]
    public string ConfigValue { get; set; } = null!;

    /// <summary>
    /// 配置类型：String, Int, Bool, Json
    /// </summary>
    [Column(StringLength = 50, IsNullable = false)]
    public string ConfigType { get; set; } = "String";

    /// <summary>
    /// 配置分组（用于 UI 分类显示）
    /// 例如：Network, Security, System
    /// </summary>
    [Column(StringLength = 100)]
    public string? Category { get; set; }

    /// <summary>
    /// 配置描述
    /// </summary>
    [Column(StringLength = 500)]
    public string? Description { get; set; }

    /// <summary>
    /// 是否需要重启服务生效
    /// </summary>
    [Column(IsNullable = false)]
    public bool RequiresRestart { get; set; } = true;

    /// <summary>
    /// 是否系统配置（不可删除）
    /// </summary>
    [Column(IsNullable = false)]
    public bool IsSystem { get; set; } = true;

    /// <summary>
    /// 是否为敏感信息（敏感信息会加密存储）
    /// 例如：密码、Token、密钥等
    /// </summary>
    [Column(IsNullable = false)]
    public bool IsSensitive { get; set; } = false;

    /// <summary>
    /// 排序
    /// </summary>
    [Column(IsNullable = false)]
    public int SortOrder { get; set; } = 0;

    /// <summary>
    /// 创建时间
    /// </summary>
    [Column(IsNullable = false)]
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

    /// <summary>
    /// 创建者
    /// </summary>
    [Column(StringLength = 100)]
    public string? CreatedBy { get; set; }

    /// <summary>
    /// 更新时间
    /// </summary>
    public DateTime? UpdatedAt { get; set; }

    /// <summary>
    /// 更新者
    /// </summary>
    [Column(StringLength = 100)]
    public string? UpdatedBy { get; set; }
}
